<template>
  <div class="app-agent">
    <br>
    <el-form ref="queryForm" size="small" :inline="true" label-width="160px" v-model="queryParams" v-show="showSearch">
      <el-form-item label="手机号" prop="phone">
        <el-input placeholder="请输入手机号" v-model="queryParams.phone" />
      </el-form-item>

      <el-form-item label="昵称" prop="nickName">
        <el-input placeholder="请输入昵称" v-model="queryParams.nickName" />
      </el-form-item>

      <!-- <el-form-item label="姓名" prop="userName">
        <el-input placeholder="请输入昵称" v-model="queryParams.userName" />
      </el-form-item> -->

      <el-form-item label="审核状态" prop="status">
        <el-select v-model="searchStatus" placeholder="请选择审核状态" clearable>
          <!-- <el-option v-for="dict in dict.type.content_type" :key="dict.value" :label="dict.label" :value="dict.value" /> -->
          <el-option label="待审核" value="0"></el-option>
          <el-option label="机审审核通过" value="1"></el-option>
          <el-option label="机审审核失败" value="2"></el-option>
          <el-option label="机审通过人工审核通过" value="3"></el-option>
          <el-option label="机审通过人工审核失败" value="4"></el-option>
          <el-option label="人工确认" value="5"></el-option>
        </el-select>
      </el-form-item>

      <!-- <el-form-item label="发布时间" prop="startTime">
        <el-date-picker clearable v-model="queryParams.startTime" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择发布时间">
        </el-date-picker>
      </el-form-item> -->

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>

    </el-form>
    <!-- 新增 -->
    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 表格 -->
    <el-table v-loading="loading" :data="userDataList" @selection-change="handleSelectionChange" label-width="100px">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->

      <el-table-column label="手机号" align="center" prop="phone" width="150"/>
      <!-- <el-table-column label="身份" align="center" prop="musicIndex" /> -->
      <el-table-column label="头像" align="center" prop="auditAvatar">
        <template slot-scope="scope">
         <img :src="scope.row.avatar" alt="" width="50px" height="50px">
        </template>
      </el-table-column>
      <el-table-column label="昵称" align="center" prop="nickName" />
      <el-table-column label="个人简介" align="center" prop="introduction" />
      <el-table-column label="审核头像" align="center" width="100" prop="auditAvatar">
        <template slot-scope="scope">
         <img :src="scope.row.auditAvatar == null?null:scope.row.auditAvatar" alt="" width="50px" height="50px">
        </template>
      </el-table-column>
      <el-table-column label="审核昵称" align="center" prop="auditNickName">
        <template slot-scope="scope">
          <span>
            {{ scope.row.auditNickName == null?null:scope.row.auditNickName }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="审核简介" align="center" prop="auditIntro">
        <template slot-scope="scope">
          <span>
            {{ scope.row.auditIntro == null?null:scope.row.auditIntro }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="examine">
        <template slot-scope="scope">
          <span>{{ scope.row.examine == 0?"待审核":scope.row.examine == 1?"机审审核通过":scope.row.examine == 2?"机审审核失败":scope.row.examine == 3?"机审通过人工审核通过":scope.row.examine == 4?"机审通过人工审核失败":scope.row.examine == 5?"人工确认":null }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="150">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['system:musicinfo:edit']">{{ scope.row.examine ==3?"修改":scope.row.examine ==4?"修改":"审核" }}</el-button>
        </template>
      </el-table-column>
    </el-table>

        <!-- 审核对话框 -->
        <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="queryParams" :rules="rules" :model="queryParams"  label-width="80px">

        <el-form-item label="是否通过" prop="status">
          <!-- <el-radio-group v-model="queryParams.status"> -->
            <el-radio v-model="queryParams.status" :label="3">人工审核通过</el-radio>
            <el-radio v-model="queryParams.status" :label="4">人工审核失败</el-radio>
          <!-- </el-radio-group> -->
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

  </div>
</template>

<script>
import { getReviewinfo,upDatainfo,upDataBackground } from "../../../api/system/dataReview"
import { regionData } from "../../../../node_modules/element-china-area-data";
export default {
  name: 'dataReview',
  // dicts: ['content_type'],
  data() {
    return {
      // right:right,
      searchStatus: null,
      // 遮罩层
      loading: true,
       // 总条数
       total: 1,
      // 用户表格数据
      userDataList: [],
       // 是否显示弹出层
       open: false,
        // 弹出层标题
      title: "",
      // 显示隐藏二级
      isFlag: false,

      multiple:true,

      form:{},
      // 显示搜索条件
      showSearch: true,
       // 表单校验
       rules: {
        status: [
          { required: true,validator: (rule, value, callback) => {
        if (value !== 3 && value !== 4) {
          callback(new Error('请选择通过或者不通过'));
        } else {
          callback();
        }
      },  trigger: "blur" }
        ],
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        nickName:null,
        phone:null,
        status:null,
        startTime:null,
        endTime:null,
        id:null
      },
    }
  },
  created() {
    this.getList();
  },
  methods: {
      // 取消按钮
      cancel() {
      this.open = false;
      this.reset();
    },

     // 表单重置
     reset() {
      this.form = {
            createTime: null,
            examine: null,
            phone: null,
            nickName: null,
            id: null,
            avatar: null,
            userId: null,
            auditAvatar: null,
            operation: null,
            introduction:null
      };
      this.resetForm("form");
    },
     /** 查询内容模块列表 */
     getList() {
      this.loading = true;
      getReviewinfo(this.queryParams).then(response => {
        this.userDataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

     // 多选框选中数据
     handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
   
     /** 搜索按钮操作 */
     handleQuery() {
      this.queryParams.pageNum = 1;
      this.queryParams.status = this.searchStatus;
      this.getList();
    },

      /** 重置按钮操作 */
      resetQuery() {
      // this.resetForm("queryForm");
      this.queryParams= {
        pageNum: 1,
        pageSize: 10,
        nickName:null,
        phone:null,
        status:null,
        startTime:null,
        endTime:null,
        id:null
      },
      this.searchStatus = null; 
      this.handleQuery();
    },

     /** 修改按钮操作 */
     handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      this.open = true;
      this.queryParams.id = row.id;
      this.queryParams.status = row.examine;
    },


       /** 提交按钮 */
    submitForm() {
      this.$refs["queryParams"].validate(valid => {
        const { id, status } = this.queryParams;
        if (valid) {
          console.log('====================================');
          console.log("表单验证通过");
          console.log('====================================');
          if (this.queryParams.status == 3 || this.queryParams.status == 4) {
            upDatainfo({id:id,status:status}).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.queryParams.status = null
              this.getList();
              
            });
          } else {
            upDataBackground({id:id,status:status}).then(response => {
              this.$modal.msgSuccess("审核成功");
              this.open = false;
              this.queryParams.status = null
              this.getList();
             
            });
          }
        }else{
          console.log('====================================');
          console.log("表单验证失败");
          console.log('====================================');
        }
      });
    },
  }

}
</script>

<style scoped>

.on_border_input >>> .el-input__inner {
  border: 0px;
}
.on_border_select >>> .el-input__inner {
  border: 0px;
  /* color: blue; */
  font-size: 12px;
}
</style>